package com.middlegroup.common.enums;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;


/**
 * @author pc
 * 代付，代扣，协议，快捷的channelCode请区分哦
 */

public enum ChannelCode {

    EMPTY0000001("EMPTY0000001", "模拟代付"),
    EMPTY0000002("EMPTY0000002", "模拟代收"),
    EMPTY0000003("EMPTY0000003", "模拟协议支付"),
    EMPTY0000004("EMPTY0000004", "模拟快捷支付"),



    CH0000001("CH0000001", "快捷通代付"),
    CH0000002("CH0000002", "合利宝代付"),
    CH0000003("CH0000003", "畅捷代付"),
    CH0000004("CH0000004", "合利宝代付D1"),
    CH0000005("CH0000005", "畅捷代付D1"),
    CH0000006("CH0000006", "合利宝代扣(协议支付)"),


    CH1111111("CH1111111", "畅捷代扣"),
    CH1111112("CH1111112", "畅捷代扣D1"),





    CH2222221("CH2222221", "先锋快捷支付"),



    CH3333331("CH3333331", "先锋协议支付"),
    CH3333332("CH3333332", "快捷通协议支付"),
    CH3333333("CH3333333", "畅捷协议支付"),

    wx_h5("wx_h5", "微信H5支付"),
    wx_sdk("wx_sdk", "微信sdk支付"),

    alipay_h5("alipay_h5", "阿里H5支付"),
    alipay_sdk("alipay_sdk", "阿里sdk支付"),

    CH5555551("CH5555551", "PaypalH5支付"),
    CH5555552("CH5555552", "Paypalsdk支付"),
    paypal("paypal", "PAYPAL支付")
    ;

    private String code;
    private String name;

    /**
     * @param code
     * @param name
     */
    ChannelCode(String code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 根据code获取name
     * @param code
     * @return
     */
    public static String getName(String code) {
        for (ChannelCode e : ChannelCode.values()) {
            if (StringUtils.equals(e.getCode(),code)) {
                return e.name;
            }
        }
        return null;
    }

    /**
     *将该枚举全部转化成json
     * @return
     */
    public static String toJson(){
        JSONArray jsonArray = new JSONArray();
        for (ChannelCode e : ChannelCode.values()) {
            JSONObject object = new JSONObject();
            object.put("code", e.getCode());
            object.put("name", e.getName());
            jsonArray.add(object);
        }
        return jsonArray.toString();
    }

    /**
     * 重写toString，单个转化成json
     * @return
     */
    @Override
    public String toString() {
        JSONObject object = new JSONObject();
        object.put("code",code);
        object.put("name",name);
        return object.toString();
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}